﻿using System.Linq;
using System.Web.Mvc;
using yiCommerce.Areas.Admin.Models.Products;
using yiCommerce.Attributes;
using yiCommerce.Service.Products;

namespace yiCommerce.Areas.Admin.Controllers
{

    [AdminAuthorize(Order = 1)]
    [AdminProductAuthorize(Order = 2)]
    public class ProductSpecificationAttributeController : Controller
    {
        //
        // GET: /ProductSpecificationAttribute/
        private IProductService _productService;


        public ProductSpecificationAttributeController(IProductService productService)
        {
            _productService = productService;
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Create(int productId)
        {

            var allSpecificationAttributes = _productService.GetAllSpecificationAttribute();

            var model = new ProductSpecificationAttributeModel
                {
                    ProductId = productId,
                    AvailableSpecificationAttributes = allSpecificationAttributes.Select(c=>new SpecificationAttributeModel()
                        {
                            Id = c.Id,
                            Name = c.Name,
                            AvailableSpecificationAttributeOptions = c.SpecificationAttributeOptions.Select(t=>new SpecificationAttributeOptionModel()
                                {
                                    Id=t.Id,
                                    Name = t.Name

                                }).ToList()
                        } ).ToList()
                };

            ViewBag.Model = model;
            return View();
        }

    }
}
